package com.company.woye.checkmakesure.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.company.woye.R;
import com.company.woye.checkmakesure.bean.MakeSureBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MakeSureListviewAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private Context mContext;
    private List<MakeSureBean> data;

    public MakeSureListviewAdapter(Context context, List<MakeSureBean> data) {
        this.inflater = LayoutInflater.from(context);
        this.mContext = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHodler = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.intem_make_sure_list_detail, parent, false);
            viewHodler = new ViewHolder(convertView);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHolder) convertView.getTag();
        }
        viewHodler.tvGroup.setText(data.get(position).getLsx());
        viewHodler.tvLabucode.setText(data.get(position).getFormNo());
        viewHodler.tvDaoci.setText(data.get(position).getKdcs());
        viewHodler.tvOrder.setText(data.get(position).getHyh());
        viewHodler.tvMakebili.setText(data.get(position).getMarkRate());
        viewHodler.tvJianyanzu.setText(data.get(position).getCheckGroup());
        viewHodler.tvCplx.setText(data.get(position).getCplx());
        viewHodler.tvJihuachangci.setText(data.get(position).getPlanBedNo());
        viewHodler.tvChangcixuhao.setText(data.get(position).getBedNo());
        viewHodler.tvSecheng.setText(data.get(position).getSc());
        if (!TextUtils.isEmpty(data.get(position).getState())){
            if (data.get(position).getState().equals("0")){
                viewHodler.ll.setBackgroundColor(Color.WHITE);
            }else {
                viewHodler.ll.setBackgroundColor(mContext.getResources().getColor(R.color.lightGreen_));
            }
        }
        return convertView;
    }




    class ViewHolder {
        @BindView(R.id.tv_group)
        TextView tvGroup;
        @BindView(R.id.tv_labucode)
        TextView tvLabucode;
        @BindView(R.id.tv_daoci)
        TextView tvDaoci;
        @BindView(R.id.tv_order)
        TextView tvOrder;
        @BindView(R.id.tv_makebili)
        TextView tvMakebili;
        @BindView(R.id.tv_jianyanzu)
        TextView tvJianyanzu;
        @BindView(R.id.tv_cplx)
        TextView tvCplx;
        @BindView(R.id.tv_jihuachangci)
        TextView tvJihuachangci;
        @BindView(R.id.tv_changcixuhao)
        TextView tvChangcixuhao;
        @BindView(R.id.tv_secheng)
        TextView tvSecheng;
        @BindView(R.id.ll)
        LinearLayout ll;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
